package com.qxsx.midi.activity.exam;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.activity.base.BaseActivity;
import com.qxsx.midi.utils.MyNet;
import com.qxsx.midi.utils.callBackJsonArray;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by LYJ on 2015/9/16.
 * 考试指南
 */
public class ExamProcessActivity extends BaseActivity implements OnClickListener {
    private WebView wv_prpcess;
    private TextView tv_bianji;
    String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exam_process);
        setTitle("考级流程");
        setNavBtn(R.mipmap.back, 0);
        findById();
        examprocess();

    }

    private void findById() {
        wv_prpcess = (WebView) findViewById(R.id.exam_webview);
    }

    @Override
    protected void HandleTitleBarEvent(TitleBar component, View v) {
        switch (component) {
            case LEFT:
                finish();
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }

    }

    /**
     * 解析
     */
    private void examprocess() {
        final JSONObject object = new JSONObject();
        JSONArray array = new JSONArray();
        try {
            object.put("article_id", "grading_process");
            array.put(object);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        MyNet.doPostJsonArray("8030", array, new callBackJsonArray() {
            @Override
            public void run(Object code, Object message, JSONArray array) {
                try {
                    JSONObject object1 = array.getJSONObject(0);
                    url = object1.getString("url");
                    wv_prpcess.loadUrl(url);
                    //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
                    wv_prpcess.setWebViewClient(new WebViewClient() {
                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            // TODO Auto-generated method stub
                            //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                            view.loadUrl(url);
                            return true;
                        }
                    });
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });

    }
}
